//https://leetcode.cn/problems/partition-equal-subset-sum/description/
//分割等和子集
class Solution {
public:
    bool canPartition(vector<int>& nums) 
    {
        int n = nums.size();
        if(n == 1) return false;
        int sum = 0;
        for(auto& e : nums) sum += e;
        if(sum % 2 == 1) return false;
        sum /= 2;

        vector<bool> dp(sum + 1);
        dp[0] = true;
        for(int i = 1; i <= n; i++)
        {
            for(int j = sum; j >= nums[i - 1]; j--)
            {
                dp[j] = dp[j] || dp[j - nums[i - 1]];
            }
        }

        return dp.back();
    }
};